//
//  AIHomeModel.m
//  aixianfeng
//
//  Created by wangwei on 2016/12/22.
//  Copyright © 2016年 lijiangbo. All rights reserved.
//

#import "AIHomeModel.h"

#import "AIHomeFocusModel.h"
#import "AIHomeIconsModel.h"
#import "AIHomeActivitiesModel.h"

#import "AIHomeItemModel.h"

#import "LEEHTTPManager.h"


@implementation AIHomeModel

IMPLEMENTATION_SINGLETON(AIHomeModel)

- (void)getDataFinshed:(void (^)(NSMutableArray<AIHomeFocusModel *> *, NSMutableArray<AIHomeIconsModel *> *, NSMutableArray<AIHomeActivitiesModel *> *, NSError *))finshed {

    NSString *urlString = @"http://iosapi.itcast.cn/loveBeen/focus.json.php";
    NSDictionary *parameters = @{@"call":@1};
    //请求数据
    [[LEEHTTPManager share] request:POST UrlString:urlString parameters:parameters finshed:^(id responseObject, NSError *error) {
        
        if (error) {
            NSLog(@"error ---%@",error);
            return ;
        }
        
       // NSLog(@"%@",responseObject);
        //json 数据解析
        NSDictionary *dict = (NSDictionary *)responseObject;
        
        NSArray *focusArray = dict[@"data"][@"focus"];
        NSArray *iconsArray = dict[@"data"][@"icons"];
        NSArray *activitiesArray = dict[@"data"][@"activities"];
        
        NSMutableArray<AIHomeFocusModel *>* focusModelArray = [NSArray yy_modelArrayWithClass:[AIHomeFocusModel class] json:focusArray].copy;
        NSMutableArray<AIHomeIconsModel *>* iconsModelArray = [NSArray yy_modelArrayWithClass:[AIHomeIconsModel class] json:iconsArray].copy;
        NSMutableArray<AIHomeActivitiesModel *> *activitiesModelArray = [NSArray yy_modelArrayWithClass:[AIHomeIconsModel class] json:activitiesArray].copy;
        
        //得到数据之后,我们需要回调
        finshed(focusModelArray,iconsModelArray,activitiesModelArray,nil);
    }];
    

}

- (void)getDataItemFinshed:(void (^)(NSMutableArray<AIHomeItemModel *> *, NSError *))complement {

    NSString *urlString = @"http://iosapi.itcast.cn/loveBeen/firstSell.json.php";
    NSDictionary *parameters = @{@"call":@2};
    
    //请求数据
    [[LEEHTTPManager share] request:POST UrlString:urlString parameters:parameters finshed:^(id responseObject, NSError *error) {
        if (error) {
            NSLog(@"error ---%@",error);
            complement(nil,error);
            return ;
        }
        
        //json 数据解析
        NSDictionary *dict = (NSDictionary *)responseObject;
        
        NSArray *array = dict[@"data"];
        NSMutableArray<AIHomeItemModel *> *modelArray = [NSArray yy_modelArrayWithClass:[AIHomeItemModel class] json:array].copy;
        complement(modelArray,error);
    }];
}


@end
